package com.qn.combination.filter;

import cn.hutool.core.util.ObjectUtil;
import com.qn.combination.core.context.ChargeContext;
import com.qn.combination.core.filter.AbstractEventFilter;
import com.qn.combination.service.IFacadeService;
import com.qn.combination.vo.Car;
import com.qn.combination.vo.ChargeRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
public class CarInfoQueryFilter extends AbstractEventFilter<ChargeContext> {

    //filter 里面 查询缓存，使用消息 ，调用其他服务
    private final IFacadeService facadeService;

    @Override
    protected void handle(ChargeContext context) {
        if (ObjectUtil.isEmpty(context.getCar())) {
            ChargeRequest chargeRequest = context.getChargeRequest();
            String carNo = chargeRequest.getCarNo();

            Car car = facadeService.getCarInfoByCarNO(carNo);

            context.setCar(car);

        }
        log.info("查询车辆信息并且放入上下文中");

    }
}
